package com.sznaner.tool.util;

import android.annotation.SuppressLint;
import android.app.KeyguardManager;
import android.content.Context;
import android.os.PowerManager;

public class PowerManagerUtil {

    /**
     * 唤醒手机屏幕并解锁
     */
    @SuppressLint("InvalidWakeLockTag")
    public static void wakeUp( ) {

        PowerManager.WakeLock wl;

        //获取电源管理器对象
        PowerManager pm=(PowerManager) NRTool.context().getSystemService(Context.POWER_SERVICE);

        //获取PowerManager.WakeLock对象，后面的参数|表示同时传入两个值，最后的是调试用的Tag
        wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "WakeUp");

        //点亮屏幕
        wl.acquire();
        wl.release();//释放锁
    }

    //屏幕是否亮屏
    public static Boolean isWakeUp(){
        PowerManager powerManager = (PowerManager) NRTool.context().getSystemService(Context.POWER_SERVICE);
        //true为打开，false为关闭
        boolean ifOpen = powerManager.isScreenOn();
        return ifOpen;
    }

}
